<template>
  <div>
    <van-nav-bar
    title="忘记密码"
    left-arrow
    @click-left="onClickLeft"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
     
      <van-field
        v-model="sms"
        center
        clearable
        label="短信验证码"
        placeholder="请输入短信验证码"
        >
        <template #button>
            <van-button size="small" type="primary" @click="yzm">发送验证码</van-button>
        </template>

    </van-field>
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
    />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { Form } from "vant";
import { Field } from "vant";

export default {
  name: "WorkspaceJsonLogin",
  components: {
    [Form.name]: Form,
    [Field.name]: Field,
  },
  data() {
    return {
        username:'',
        sms:'',
        password:''
    };
  },

  mounted() {},

  methods: {
    onSubmit(values) {
      let{username,password,sms}=this
      this.$http.post('/user/forget',{
        username,
        password,
        vercode:sms
      })
      .then(res=>{
        console.log(res);
        this.$toast(res.msg);
        setTimeout(()=>{
          this.$router.go(-1);
        },800)
      })
    },
    // 返回上一级
    onClickLeft(){
        this.$router.go(-1)
    },
    // 获取验证码
    yzm(){
      let{username}=this
      this.$http.post('/user/sendSms',{
          mobile:username,
          type:'login' 
      })
      .then(res=>{
        console.log(res);
      })
    }

  },
};
</script>

<style lang="scss" scoped>
</style>